var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("DirBeanData"),
    c = t("BaseRoadCatDataCom"),
    p = t("CatAnimal"),
    l = t("CatStatusCom"),
    d = t("CatViewSprite"),
    u = cc._decorator,
    h = u.ccclass,
    f = u.property,
    y =
        (u.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.catStatus = null;
                e.catMoveData = new s.default();
                e.skinCom = null;
                e.statusLab = null;
                e.cookMul = 1;
                e.isWanMei = !1;
                e.catAnimal = null;
                e.tss = 0;
                e.offDisIndex = 30;
                e.checkIndex = r.Cat0Index.continueWait;
                e.roadIndex = 0;
                e.isCooking = !1;
                e.lastBool = !1;
                e.setMoveDir = !0;
                e.isRemoveInvate = !1;
                e.isPlayAnimalSleep = !1;
                return e;
            }
            e.prototype.updateCheckCs = function (t, e) {
                if (this.curMoveWayAren == e && this.moveCs > 0 && !CacheDataManager.getFoodTabStatus(this.roadIndex)) {
                    for (var o = [], a = 0; a < this.movePath.length; a++) o.push(this.movePath[a]);
                    this.moveCs--;
                    this.pathIndexOff = this.getPathDisToIndex(o, this.moveCs * this.offDisIndex);
                    this.setPath(o);
                    this.startMoveNode(null, this.checkWaitMove.bind(this));
                }
            };
            e.prototype.checkWaitMove = function () {
                this.pathIndex++;
                if (
                    this.movePath &&
                    this.movePath[this.pathIndex] &&
                    this.pathIndex < this.movePath.length - this.pathIndexOff
                ) {
                    this.startMoveNode(null, this.checkWaitMove.bind(this));
                    CacheDataManager.setFoodTab(this.roadIndex, !0);
                } else {
                    r.Cat0Index.waitFood != this.checkIndex && this.checkTask();
                    CacheDataManager.setFoodTab(this.roadIndex, !1);
                    EvCat.emit(EvCat.updateCheckView);
                }
            };
            e.prototype.update = function (e) {
                t.prototype.update.call(this, e);
                this.catMoveData.setCurPos(this.node.y);
                this.statusLab.string = " id:" + this.id + "moveCs:" + this.moveCs;
            };
            e.prototype.checkViewSprite = function () {
                this.skinCom || (this.skinCom = this.node.getComponent(d.default));
            };
            e.prototype.setSkinData = function (t) {
                this.skinFront = t;
            };
            e.prototype.setEquip = function (t, e) {
                this.equipSkin = t;
                this.checkViewSprite();
                this.skinCom.setHatPos(e);
            };
            e.prototype.setFrontView = function () {
                this.checkViewSprite();
                if (this.skinCom && this.skinFront && this.skinFront.front) {
                    this.lastBool = !0;
                    var t = this.skinFront.front;
                    this.skinCom.setFrontSkin(t.Body_Front, t.Eyes, t.Face, t.Hand, t.Tail);
                    this.setEquitFrontView();
                }
            };
            e.prototype.setBackView = function () {
                this.checkViewSprite();
                if (this.skinCom && this.skinFront && this.skinFront.back) {
                    this.lastBool = !1;
                    var t = this.skinFront.back;
                    this.skinCom.setBackSkin(t.Body_Back, t.Tail, t.Hand);
                    this.setEquitBackView();
                }
            };
            e.prototype.setEquitFrontView = function () {
                if (this.skinCom && this.equipSkin && this.equipSkin.front) {
                    var t = this.equipSkin.front;
                    this.skinCom.setFrontEquit(t.hat, t.wear, t.arms);
                }
            };
            e.prototype.setEquitBackView = function () {
                if (this.skinCom && this.equipSkin && this.equipSkin.back) {
                    var t = this.equipSkin.back;
                    this.skinCom.setBackEquit(t.hat, t.wear, t.arms);
                }
            };
            e.prototype.checkRoadPathDir = function (t) {
                "1" == CacheDataManager.getCacheDirIndex(t) ? this.setFrontView() : this.setBackView();
            };
            e.prototype.checkDoTask = function (t) {
                this.checkIndex = t.task;
                switch (t.task) {
                    case r.Cat0Index.moveWalk:
                        this.tss = 1;
                        this.pathIndex = 0;
                        this.moveCs = t.cs || 0;
                        this.roadIndex = t.index;
                        this.pathIndexOff = this.getPathDisToIndex(t.path, this.moveCs * this.offDisIndex);
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        this.playWalkAnimal();
                        break;
                    case r.Cat0Index.moveGetFoodData:
                        this.tss = 2;
                        this.pathIndex = 0;
                        this.moveCs = t.cs || 0;
                        this.pathIndexOff = this.getPathDisToIndex(t.path, this.moveCs * this.offDisIndex);
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveGetFoodOver.bind(this));
                        this.playWalkAnimal();
                        break;
                    case r.Cat0Index.waitFood:
                        this.tss = 3;
                        this.playWaitAnimal();
                        this.checkRoadPathDir(t.index);
                        TaskGameEvent.emit(TaskGameEvent.taskKind, this.kind, this.id, this.moveAren, t);
                        break;
                    case r.Cat0Index.moveOverFood:
                        this.tss = 4;
                        this.catStatus && this.catStatus.unStatus();
                        this.pathIndex = 0;
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        this.playWalkAnimal();
                        TaskGameEvent.emit(TaskGameEvent.roadCatLeave, t.index, t.cs, "0");
                        EvCat.emit(EvCat.recCatCall, this.kind, "0");
                        break;
                    case r.Cat0Index.continueWait:
                        this.tss = 5;
                        this.playSeelpWait();
                        TaskGameEvent.emit(TaskGameEvent.taskKind, this.kind, this.id, this.moveAren, t);
                        this.isRemoveInvate && this.startInvate();
                        break;
                    case r.Cat0Index.removeFoodKind:
                        this.tss = 6;
                        TaskGameEvent.emit(TaskGameEvent.removeTabFood, t);
                        var e = t.toId + "";
                        this.cookMul = t.cookMul;
                        this.catStatus.viewFoodTip(
                            e,
                            CacheDataManager.getMulProfit(e, CacheDataManager.getFoodLevel(e), this.cookMul)
                        );
                        this.checkTask();
                        break;
                    case r.Cat0Index.moveToDlg:
                        this.tss = 7;
                        this.playWalkAnimal();
                        if (t.startToPos) this.movePath = [];
                        else {
                            this.pathIndex = 0;
                            this.setPath(t.path);
                        }
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        break;
                    case r.Cat0Index.dlg:
                        this.tss = 8;
                        this.playWaitAnimal();
                        this.catStatus && this.catStatus.viewWait(t.waitTime, t, this.dlgOver.bind(this));
                        break;
                    case r.Cat0Index.cooking:
                        this.tss = 9;
                        var o = t.toTab2Index;
                        this.playCookAnimal(o);
                        if (this.catStatus) {
                            this.doCookAnimal(t);
                            this.catStatus.viewWait(t.waitTime, t, this.cookingOver.bind(this));
                        }
                        break;
                    case r.Cat0Index.downFood:
                        this.tss = 10;
                        this.catStatus && this.catStatus.unStatus();
                        TaskGameEvent.emit(
                            TaskGameEvent.downFood,
                            this.cookMul,
                            t.index,
                            t.toTab2Index,
                            t.toId2,
                            t.toId,
                            t.count,
                            t.toAren,
                            this.isWanMei,
                            this.catStatus.getTipStr()
                        );
                        this.moveOver();
                        this.isRemoveInvate && this.startInvate();
                }
            };
            e.prototype.doCookAnimal = function (t) {
                TaskGameEvent.emit(TaskGameEvent.setFoodDevData, t.toId, t.toId2, !0);
            };
            e.prototype.cookOverAnimal = function (t) {
                TaskGameEvent.emit(TaskGameEvent.setFoodDevData, t.toId, t.toId2, !1);
            };
            e.prototype.updateFoodStatus = function (t, e) {
                this.checkEvent && t == this.id && this.catStatus && (this.catStatus.wantFood(e) || this.checkTask());
            };
            e.prototype.cookingOver = function (t) {
                this.cookOverAnimal(t);
                this.cookMul = 1;
                this.isWanMei = !1;
                if (CacheDataManager.isPerfectRateAdd(this.id + "", this.kindIndex + "")) {
                    this.cookMul = CacheDataManager.addWanMeiTime;
                    this.isWanMei = !0;
                }
                CacheDataManager.isInvateId(this.id) &&
                    (this.cookMul += CacheDataManager.getAddCatAddtion(this.id, "3", r.AddtionData.allFoodAdd));
                TaskGameEvent.emit(TaskGameEvent.setCookStatus, t.toId2, !1);
                if (this.catStatus) {
                    var e = t.toId + "";
                    this.catStatus.viewFoodTip(
                        e,
                        CacheDataManager.getMulProfit(e, CacheDataManager.getFoodLevel(e), this.cookMul)
                    );
                }
                QAudio.play(QAudio.effect_cook);
                this.moveOver();
            };
            e.prototype.dlgOver = function (t) {
                this.catStatus && this.catStatus.unStatus();
                this.moveOver();
                TaskGameEvent.emit(TaskGameEvent.addCookTask, t.index, t.toId);
            };
            e.prototype.addEvWaitFood = function () {};
            e.prototype.dirViewNode = function (t) {
                var e, o;
                if (!this.isPlayAnimalSleep) {
                    this.setMoveDir = t;
                    if (this.lastBool != t)
                        if (t) {
                            this.setFrontView();
                            null === (e = this.catAnimal) || void 0 === e || e.setDirList(!0);
                        } else {
                            this.setBackView();
                            null === (o = this.catAnimal) || void 0 === o || o.setDirList(!1);
                        }
                }
            };
            e.prototype.updateViewSkin = function () {
                var t, e;
                if (this.lastBool) {
                    this.setFrontView();
                    null === (t = this.catAnimal) || void 0 === t || t.setDirList(!0);
                } else {
                    this.setBackView();
                    null === (e = this.catAnimal) || void 0 === e || e.setDirList(!1);
                }
            };
            e.prototype.setBaseData = function (e, o, a, i, n) {
                t.prototype.setBaseData.call(this, e, o, a, i, n);
                this.setMoveDir = !0;
                this.isCooking = !1;
                this.updateSpeeds();
                this.setFrontView();
                this.cookMul = 1;
                this.catMoveData.setCall(this.dirViewNode.bind(this));
                if (!this.catAnimal) {
                    var r = this.node.getComponent(p.default);
                    this.catAnimal = r;
                }
                if (!this.catStatus) {
                    r = this.node.getComponent(l.default);
                    this.catStatus = r;
                }
                this.checkTask();
            };
            e.prototype.moveOver = function () {
                if (this.pathIndex >= this.movePath.length - 1 - this.pathIndexOff) this.checkTask();
                else {
                    this.pathIndex++;
                    this.startMoveNode(null, this.moveOver.bind(this));
                }
            };
            e.prototype.moveGetFoodOver = function () {
                this.moveOver();
            };
            e.prototype.checkTask = function () {
                if (this.taskList.length > 0 && this.taskIndex < this.taskList.length) {
                    var t = this.taskList[this.taskIndex];
                    this.taskIndex++;
                    this.checkDoTask(t);
                } else {
                    this.clearData();
                    this.recNode();
                }
            };
            e.prototype.removeInvate = function () {
                t.prototype.removeInvate.call(this);
                if (this.kind == r.catKind.npcCat && CacheDataManager.isInvateId(this.id)) {
                    this.isRemoveInvate = !0;
                    this.checkIndex == r.Cat0Index.continueWait && this.startInvate();
                }
            };
            e.prototype.startInvate = function () {
                if (this.isRemoveInvate) {
                    CacheDataManager.resetInvate(this.id);
                    TaskGameEvent.emit(TaskGameEvent.removeNpcId, [this.id]);
                    this.isRemoveInvate = !1;
                    this.clearData();
                    this.recNode();
                }
            };
            e.prototype.playWalkAnimal = function () {
                this.isCooking = !1;
                this.isPlayAnimalSleep = !1;
                if (this.catAnimal) {
                    this.catAnimal.playWalk();
                    this.catAnimal.playRotate();
                }
            };
            e.prototype.playWaitAnimal = function () {
                this.isPlayAnimalSleep = !1;
                this.catAnimal && this.catAnimal.playWait();
            };
            e.prototype.playCookAnimal = function (t) {
                this.isPlayAnimalSleep = !1;
                if (this.catAnimal) {
                    this.isCooking = !0;
                    this.catAnimal.playCooking(t) ? this.setFrontView() : this.setBackView();
                }
            };
            e.prototype.playSeelpWait = function () {
                this.isCooking = !1;
                this.isPlayAnimalSleep = !0;
            };
            e.prototype.updateCheckAnimal = function () {
                if (this.isPlayAnimalSleep) {
                    this.isPlayAnimalSleep = !1;
                    this.catAnimal && this.catAnimal.playWait();
                }
            };
            n([f(cc.Label)], e.prototype, "statusLab", void 0);
            return n([h], e);
        })(c.default));
o.default = y;
